<?php


namespace app\login\service;


use app\common\controller\Sign;
use app\common\model\Sign as SignModel;
use Driver\Cache\Redis;

class CountService
{
    # 获取
    public function getSignCountData($name)
    {
        $user_id = $this->get_account_id($name);
        $all_sign_registered = $this->get_sign_registered($user_id);
        $count_arr = $this->count_every_sign_by_registered($all_sign_registered);
        return $count_arr;
    }

    # 通过name从redis获取到对应的id
    private function get_account_id($name)
    {
        $redis_hash_key = config('redis.account').$name;
        return Redis::hget($redis_hash_key, 'id');
    }

    # 获取当前账户的所有标识的所有注册记录
    private function get_sign_registered($user_id)
    {
        $model = new SignModel();
        return $model->everySignData($user_id);
    }

    # 获取每个标识的注册记录并进行统计
    private function count_every_sign_by_registered($all_sign_registered)
    {
        $arr = [];
        foreach ($all_sign_registered as $sign){
            if($sign['registered'] == ''){
                $count_null = $this->list_registered_null($sign['sign']);
                array_push($arr, $count_null);
            }
            $common = new Sign();
            $count_arr = $common->Sign($sign['sign'], $sign['registered']);
            array_push($arr, $count_arr);
        }
        return $arr;
    }

    private function list_registered_null($sign)
    {
        return [
            'd_status_arr' => [0=>1, 1=>0, 2=>0, 3=>0, 4=>0, 5=>0, 6=>0, 7=>0, 8=>0, 9=>0, 19=>0, 20=>0, 21=>0],
            'f_status_arr' => [0=>1, 1=>0, 2=>0, 3=>0, 4=>0, 5=>0, 6=>0, 19=>0, 20=>0, 21=>0, -5=>0, -4=>0, -2=>0],
            'd_time_arr' => ['today'=>0, 'yesterday'=>0, 'week'=>0, 'month'=> 0],
            'f_time_arr' => ['today'=>0, 'yesterday'=>0, 'week'=>0, 'month'=> 0],
            'sign' => $sign
        ];
    }

}